package com.zql.LeetCode;

import java.util.HashMap;
import java.util.Map;

/**
 * Created By ShuHua on 2021/10/19.
 */
public class LengthOfLongestSubstring_3 {
    public static Integer lengthOfLongestSubstring(String s){
        Map<Character,Integer> window = new HashMap<>();

        int max=0;
        int left =0;
        int right=0;
        char[] s1 = s.toCharArray();
        while (right<s.length()){
            char c = s1[right];
            right++;
            window.put(c,window.getOrDefault(c,0)+1);

            while (window.get(c)>1){
                char c1 = s1[left];
                left++;

                window.put(c1,window.get(c1)-1);
            }
            max = Math.max(max,right-left);

        }
        return max;
    }

    public static void main(String[] args) {
        String s = "pwwkew";
        System.out.println(lengthOfLongestSubstring(s));
    }
}
